<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>Fluenty Survey</title>
    <style>
      body {
        margin: 0 auto;
        padding: 0;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
          'Helvetica Neue', sans-serif;
        background-color: #fff;
        max-width: 600px;
      }
      .container {
        padding: 20px;
      }
      .nav-progress-container {
        display: flex;
        align-items: center;
        margin-bottom: 30px;
        gap: 15px;
      }
      .back-button {
        width: 30px;
        height: 30px;
        border: none;
        background: none;
        cursor: pointer;
        color: #2b85e4;
        font-size: 20px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .back-button svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
      }
      .progress-bar {
        flex: 1;
        height: 6px;
        background-color: #e0e0e0;
        border-radius: 3px;
      }
      .progress {
        height: 100%;
        width: 76.59%;
        background-color: #2b85e4;
        border-radius: 3px;
      }
      .title {
        font-size: 36px;
        font-weight: bold;
        color: #0B4983;
        margin-bottom: 15px;
        line-height: 1.3;
        text-align: center;
      }
      .subtitle {
        font-size: 22px;
        font-weight: 600;
        color: #333;
        margin-bottom: 25px;
        text-align: center;
      }
      .words-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 12px;
        margin-bottom: 30px;
      }
      .word-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 16px;
        border: 1px solid #e0e0e0;
        border-radius: 50px;
        background-color: white;
        cursor: pointer;
        flex-grow: 0;
      }
      .word-item.selected {
        background-color: #e6f4ff;
        border-color: #2b85e4;
      }
      .word-item:hover {
        border-color: #2b85e4;
      }
      .word-text {
        font-size: 18px;
        font-weight: 500;
        color: #333;
      }
      .word-checkbox {
        width: 22px;
        height: 22px;
        border: 2px solid #e0e0e0;
        border-radius: 50%;
        flex-shrink: 0;
        margin-left: 10px;
      }
      .word-item.selected .word-checkbox {
        border-color: #2b85e4;
        position: relative;
      }
      .word-item.selected .word-checkbox::after {
        content: '';
        position: absolute;
        width: 12px;
        height: 12px;
        background-color: #2b85e4;
        border-radius: 50%;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
      .continue-button {
        background-color: #3b82f6;
        color: white;
        border: none;
        border-radius: 12px;
        padding: 16px;
        font-size: 18px;
        font-weight: bold;
        width: 100%;
        cursor: pointer;
        text-align: center;
        margin-top: 20px;
      }
      .continue-button:hover {
        background-color: #2563eb;
      }
      @media (max-width: 480px) {
        .word-item {
          min-width: calc(50% - 12px);
        }
        .title {
          font-size: 32px;
        }
        .subtitle {
          font-size: 20px;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="nav-progress-container">
        <button class="back-button">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
          </svg>
        </button>
        <div class="progress-bar"><div class="progress"></div></div>
      </div>
      <h1 class="title">Select all the words you know:</h1>
      <h2 class="subtitle">B1-B2 Intermediate Level</h2>
      <div class="words-container">
        <div class="word-item" style="min-width: 120px">
          <span class="word-text">argument</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 100px">
          <span class="word-text">explain</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 120px">
          <span class="word-text">neighbor</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 140px">
          <span class="word-text">opportunity</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 140px">
          <span class="word-text">knowledge</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 140px">
          <span class="word-text">relationship</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 120px">
          <span class="word-text">challenge</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 100px">
          <span class="word-text">prepare</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 160px">
          <span class="word-text">disappointment</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 140px">
          <span class="word-text">concentrate</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 140px">
          <span class="word-text">compromise</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 110px">
          <span class="word-text">creative</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 180px">
          <span class="word-text">recommendation</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 160px">
          <span class="word-text">responsibility</span>
          <div class="word-checkbox"></div>
        </div>
        <div class="word-item" style="min-width: 120px">
          <span class="word-text">ambition</span>
          <div class="word-checkbox"></div>
        </div>
      </div>
      <button class="continue-button">Continue</button>
    </div>
    <script>
      document.addEventListener('DOMContentLoaded', function () {
        const wordItems = document.querySelectorAll('.word-item');
        const backButton = document.querySelector('.back-button');
        const continueButton = document.querySelector('.continue-button');
        let selectedWords = [];
        const pageName = window.location.pathname.split('/').pop().split('.')[0];

        // 检查本地存储中是否有之前选中的选项
        const storedData = localStorage.getItem(pageName);
        if (storedData) {
          const parsedData = JSON.parse(storedData);
          selectedWords = parsedData.words;
          wordItems.forEach(item => {
            const wordText = item.querySelector('.word-text').textContent;
            if (selectedWords.includes(wordText)) {
              item.classList.add('selected');
              item.style.backgroundColor = '#EBF5FF'; // 设置选中卡片背景颜色
            }
          });
        }

        wordItems.forEach(item => {
          item.addEventListener('click', function () {
            this.classList.toggle('selected');
            if (this.classList.contains('selected')) {
              this.style.backgroundColor = '#EBF5FF'; // 设置选中卡片背景颜色
            } else {
              this.style.backgroundColor = 'white'; // 移除背景颜色
            }
            const wordText = this.querySelector('.word-text').textContent;
            if (this.classList.contains('selected')) {
              if (!selectedWords.includes(wordText)) {
                selectedWords.push(wordText);
              }
            } else {
              const index = selectedWords.indexOf(wordText);
              if (index > -1) {
                selectedWords.splice(index, 1);
              }
            }
          });
        });

        backButton.addEventListener('click', function () {
          window.location.href = 'selectAllA.html';
        });

        continueButton.addEventListener('click', function () {
          if (selectedWords.length > 0) {
            // 获取页面标题和当前页面名称
            const pageTitle = document.querySelector('.title')
              ? document.querySelector('.title').textContent.trim()
              : 'Select all the words you know';
            const subtitle = document.querySelector('.subtitle')
              ? document.querySelector('.subtitle').textContent.trim()
              : 'B1-B2 Intermediate Level';

            // 创建数据对象
            const data = {
              title: pageTitle,
              subtitle: subtitle,
              value: selectedWords.join(', '), // 用逗号分隔多个选择
              words: selectedWords, // 保存为数组，便于后续处理
              count: selectedWords.length, // 选择的单词数量
              level: 'intermediate', // 词汇级别
            };

            // 以JSON格式存储到localStorage
            localStorage.setItem(pageName, JSON.stringify(data));

            window.location.href = 'selectAllC.html';
          } else {
            alert('Please select at least one word before continuing');
          }
        });
      });
    </script>
  </body>
</html>
